{% extends "base/base.html" %}

{% comment %}

 Copyright 2013 - Tom Alessi

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and 
 limitations under the License.

{% endcomment %}


{% block content %}


<script type="text/javascript">
$(function () {
        
        $('#graph').highcharts({
            credits: {
              enabled: false
            },
            chart: {
                type: 'spline',
                marginRight: 10,
                marginBottom: 75
            },
            title: {
                text: 'Total First Page Rankings',
                x: -20 //center
            },
            xAxis: {
                categories: [

                 {% for item in first_page reversed%}
                  {% if forloop.last %}
                   {% for date,value in item.items %}
                     '{{date}}'
                   {% endfor %}

                  {% else %}
                   {% for date,value in item.items %}
                     '{{date}}',
                   {% endfor %}
                  {% endif %}
                 {% endfor %}

                ],
                labels: {
                    rotation: 290,
                    y: 30
                }
            },
            yAxis: {
                title: {
                    text: null
                },
            },
            legend: {
                enabled: false
            },
            series: [{
                name: 'Count',
                data: [
                 {% for item in first_page reversed%}
                  {% if forloop.last %}
                   {% for date,value in item.items %}
                     {{value}}
                   {% endfor %}

                  {% else %}
                   {% for date,value in item.items %}
                     {{value}},
                   {% endfor %}
                  {% endif %}
                 {% endfor %}

                ],
                color: '#1c94c4'
            }]
        });
});
</script>

<div class="row">
  <div class="large-4 columns">
    <table class="history">
    <tr>
     <td style="text-align:left;">Target:<b>{{domain}}</b></td>
     <td width="10"></td>
     <td style="text-align:left;">Keywords:<b>{{keyword_count}}</b></td>
    </tr>
    <tr>
     <td style="text-align:left;">Search Country:<b>{{gl}}</b></td>
     <td width="10"></td>
     <td style="text-align:left;">Google Domain:<b>{{googlehost}}</b></td>
    </tr>
    </table>
  </div>
</div>

<div class="row">
  <div class="spacer_small"></div>
</div>


<div class="row">
  <div class="large-4 columns left">
    <div id="graph" class="graph_container" style="width:350px; height:300px;"></div>
    <div class="spacer_small"></div>
  </div>


  <div class="large-4 columns large-offset-1 left">
    <table>
    <tr>
     <th colspan="4">
      Keyword Position Changes
     </th>
    </tr>
    <tr>
      <th width="100">Since</th>
      <th colspan="3">Changes</th>
    </tr>
    {% for date,values in changes %}
    <tr>
     <td width="100">{{date}}</td>
     <td align="center"><img src="/html/images/up.png"><font size="4"> {{values.up}}</font></td>
     <td align="center"><img src="/html/images/down.png"><font size="4"> {{values.down}}</font></td>
     <td align="center"><img src="/html/images/unch.png"><font size="4"> {{values.unch}}</font></td>
    </tr>
    {% endfor %}
    </table>
  </div>
</div>


<table class="responsive">
<thead>
 <tr>

 {# Add the headings - these can be iterated over if all data are desired in the table #}
 
  <th>{{headings.0}}</th>
  <th>{{headings.1}} ({{headings.2}})</th>
  <th style="width:100px;">Rank ({{headings.2}})</th>
  <th>History</th>

 </tr>
</thead>
<tbody>
 {% for keyword,data in ranks %}
 <tr>
  <td><a href="/keyword_rank/trends?domain={{domain}}&keyword={{keyword}}&gl={{gl}}&googlehost={{googlehost}}">{{keyword}}</a></td>
  
  {# First the data - these can be iterated over if all dates are desired #}
   <td>{{data.0}}</td>
   <td>{{data.1}}</td>
 
 
  {# Now the small chart #}
  <td>
   {% for sc_keyword,data in small_charts.items %}
    {% if sc_keyword == keyword %}
     
      {# match, so draw the chart #}
        <script type="text/javascript">
        $(function () {
                
                // Vulnerability Chart
                $('#chart_div_{{keyword|urlencode|slugify|escapejs}}').highcharts({
                    credits: {
                      enabled: false
                    },
                    chart: {
                        type: 'spline',
                        marginRight: 10,
                        marginBottom: 5
                    },
                    title: {
                        text: null
                    },
                    xAxis: {
                        categories: [

                        {% for item in data %}
                          {% if forloop.last %}
                            '{{item.date|date:"Y-m-d"}}'
                          {% else %}
                            '{{item.date|date:"Y-m-d"}}',
                          {% endif %}
                        {% endfor %}

                        ],                      
                        labels: {
                          enabled: false
                        },
                        lineWidth: 0,
                        minorGridLineWidth: 0,
                        lineColor: 'transparent',
                        tickColor: 'transparent'
                    },
                    yAxis: {
                        title: {
                            text: null
                        },
                        labels: {
                          enabled: false
                        },
                        gridLineColor: 'transparent'
                    },
                    legend: {
                      enabled: false
                    },
                    series: [{
                        name: 'rank',
                        data: [

                        {% for item in data %}
                          {% if forloop.last %}
                            {{item.rank}}
                          {% else %}
                            {{item.rank}},
                          {% endif %}
                        {% endfor %}

                        ],
                        color: '#1c94c4'
                    }],
                    plotOptions: {
                      spline: {
                        lineWidth: 1,
                        marker: {
                          radius: 2
                        }

                      }
                    }
                });
        });
        </script>

      <div id="chart_div_{{keyword|urlencode|slugify|escapejs}}" class="graph_container" style="width:150px; height:100px;"></div>

    {% endif %}
   {% endfor %}
  </td>
 </tr>
{% endfor %}
</tbody>
</table>



<script type="text/javascript" src="/html/js/highcharts.js"></script>
{% endblock %}


